package com.syni.mdd.yhd.common.all.service;

import com.syni.mdd.yhd.common.all.constants.Constants;
import com.syni.mdd.yhd.common.all.constants.ResultCode;
import com.syni.mdd.yhd.common.all.constants.ResultMsg;
import com.syni.mdd.yhd.common.all.dao.jpa.BmsUserReportUserDao;
import com.syni.mdd.yhd.common.all.entity.BmsUserReportUser;
import com.syni.mdd.yhd.common.all.entity.user.BmsUser;
import com.syni.mdd.yhd.common.all.service.impl.BaseService;
import com.syni.mdd.sjb.common.component.utils.common.utils.ResultMapHelper;
import com.syni.mdd.yhd.common.all.utils.TokenManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.Map;

/**
 * @className
 * @description TOO
 * @Author cfx
 * @DATE 2019/4/9 12:04
 * @VERSION 1.0
 **/
@Service
public class BmsUserReportUserService extends BaseService<BmsUserReportUser, Integer> {
    @Autowired
    BmsUserReportUserDao bmsUserReportUserDao;

    @Override
    public BmsUserReportUserDao getBaseDao() {
        return bmsUserReportUserDao;
    }

    public Map<String, Object> reportUser(Integer userId, Integer reportedId, Integer reportType, String reportContent) {
        BmsUser reportUser = TokenManager.getUser(userId);
        if(reportUser == null){
            return ResultMapHelper.result(ResultCode.CODE_USER_NO_EXIST,"用户不存在");
        }
        BmsUser reportedUser = TokenManager.getUser(reportedId);
        if(reportedUser == null){
            return ResultMapHelper.result(ResultCode.CODE_USER_NO_EXIST,"被举报用户不存在");
        }
        BmsUserReportUser bmsUserReportUser = new BmsUserReportUser();
        bmsUserReportUser.setReportedId(reportedId);
        bmsUserReportUser.setReportedDxshh(reportedUser.getDxshh());
        bmsUserReportUser.setReportId(userId);
        bmsUserReportUser.setReportDxshh(reportUser.getDxshh());
        bmsUserReportUser.setReportType(reportType);
        bmsUserReportUser.setSupplement(reportContent);
        bmsUserReportUser.setReportTime(new Date());
        bmsUserReportUser.setReportStatus(Constants.COMMON_FLAG_FALSE_INT);
        bmsUserReportUserDao.save(bmsUserReportUser);
        return ResultMapHelper.success(ResultMsg.HAND_SUCCESS);
    }
}
